<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Master extends CI_Controller {

	public function __construct()
	{
		parent::__construct();

		$this->load->database();
		$this->load->helper('url');
		$this->load->helper('form');
		$this->load->library('grocery_CRUD');
		$this->load->model('grid_model');
		$this->developer = $this;

		$this->developer_config = $this->config->item('developer');
		$this->acl_config = $this->config->item('acl');
		$this->menu_config = $this->config->item('menu');


	}
	public function change_current_user_password()
	{
		$id = $this->LoginInfo->GetUserInfo('id_pengguna');
		echo $id;
		redirect('master/pengguna/edit/' . $id . '?change_password=true');
	}

	public function user_password($id,$return=0)
	{
		$new_passwd = $this->input->post('passwd');
		$r = array('s'=>0,'m'=>'Password tidak berhasil diganti.');
		if(!empty($id) && !empty($new_passwd) )
		{
			if(!$this->LoginInfo->validate_password($new_passwd))
			{
				$r['m'] = 'Password tidak boleh special karakter.';
			}
			else if(strlen($new_passwd) >= 6)
			{
				$pengguna = $this->db->where('id',$id)->get('users')->row();
				if($pengguna)
				{
					$this->db->where('id',$id)->update('users',array('userpassword'=>$this->LoginInfo->encrypt_password($new_passwd)));
					$r['m'] = 'Password berhasil diganti.';
					$r['s'] = 1;
				}	
			}

		}else{
			$r['m'] = 'Password anda kosong';
		}
		
		if($return)
			return $r;

		echo json_encode($r);
	}


	function encrypt_password_callback($post_array, $pk = null){
		if ($post_array['password'] <> '') {
			if($pk)
			{
				$current_user_password = $this->db->where('id_pengguna',$pk)
												  ->select('password')
												  ->get('pengguna')
												  ->row()->password;
				if($post_array['password']==$current_user_password)
					unset($post_array['password']);
				else
					$post_array['password']=$this->LoginInfo->encrypt_password( $post_array['password']);
			}
			else
			{
	        	$post_array['password']=$this->LoginInfo->encrypt_password( $post_array['password']);
	        }
	        unset( $post_array['confirm_password']);
	    }
	    return $post_array;
	}

	function valid_password($str) {
		if(strlen($str) < 6 )
		{
			$this->grid->get_form_validation()->set_message('valid_password',"%s Minimal 6 karakter.");
			return FALSE;
		}
		// if(!$this->LoginInfo->validate_password($str) )
		// {
		// 	$this->grid->get_form_validation()->set_message('valid_password',"%s Tidak boleh berisi special karakter.");
		// 	return FALSE;
		// }
	    
	    return TRUE;
	}
	function unique_value($field)
	{
		$state = $this->grid->getState();
		$count_same_field =0;

		if( $state == 'insert_validation' )
		{
			$count_same_field = $this->db->where(array($this->unique_fields => $field))
											->select('COUNT('.$this->pk.') as count')->get($this->table)->row()->count;
		}
		else if( $state == 'update_validation' )
		{

			 $state_info = $this->grid->getStateInfo();
			 $pk = $state_info->primary_key;

			 //die($pk);

			 $count_same_field = $this->db->where(array($this->unique_fields =>$field,$this->pk .' <>'=>$pk))
											->select('COUNT('.$this->pk.') as count')->get($this->table)->row()->count;
			//die( $count_same_field);
		}

	    if($count_same_field > 0)
	    {
	    	$this->grid->get_form_validation()->set_message('unique_value',ucfirst("%s sudah digunakan."));
	    }
	    return !$count_same_field;
	}
	
	public function pengguna($act='')
	{

		//$this->load->vars('list_title','User Management');
		//$this->load->vars('tool_action_width','69px');

		$grid = new grocery_CRUD();
		

		//$this->grid->get_form_validation()->set_message('required','Anda belum menginputkan %s.');
		//SET THEME
		$grid->set_theme('flexigrid');
		// $change_password = false;
		// if($this->input->get('change_password')=='true')
		// {
		// 	$this->session->set_userdata('change_password',true);
		// }
		// else
		// {
		// 	$change_password = 
		// }

		// SET GUI CAPTION
		if($act=='edit' && $this->input->get('change_password')=='true')
		{
			$this->load->vars('change_password',true);
			$grid->unset_back_to_list();
		}
		//$grid->set_caption('list_title','User Management');
		//$grid->set_table_width();
		//$grid->set_css();
		//$grid->set_tool_action_width(68);
		// MUST BE SET FOR SQL SERVER
		//$grid->order_by('id','asc');

		//SET TABLE
		$grid->set_table('pengguna');
		
		// SET DISPLAYED COLUMN
		$grid->columns('nip','id_group','status');
		$grid->fields('nip','id_group','password','confirm_password','status');
		
		// SET SUBJECT
		$grid->set_subject('Pengguna');

		// UNSET UNECESSARY FIELD
		//$grid->unset_fields('userpassword','keluar_terakhir','masuk_terakhir','email');
		$grid->unset_columns('password');
		//$grid->set_rules('userpassword', 'Password', 'required|callback_valid_password');
		$grid->set_rules('confirm_password', 'Confirm Password', 'required|matches[password]');

		$grid->callback_before_insert(array($this,'encrypt_password_callback'));
		$grid->callback_before_update(array($this,'encrypt_password_callback'));

		// $grid->callback_before_insert(array($this,'username_check_callback'));
		// $grid->callback_before_update(array($this,'username_check_callback'));

		// CHANGE TO DROPDOWN
		$nip_list = $this->grid_model->pegawai_dropdown();
		$grid->field_type('nip','dropdown',$nip_list);

		$nip_list_exist = $this->grid_model->pengguna_nip_exist();

		$this->load->vars('nip_list_exist',$nip_list_exist);
		

		$grid->field_type('status','dropdown',array('Aktif'=>'Aktif','Inaktif'=>'Inaktif'));
		

		$grid->field_type('password','password');
		$grid->field_type('confirm_password','password');
		
		$grid->set_relation('id_group','group_pengguna','group');
		// CHANGE CAPTION
		//$grid->display_as('userpassword','Password');
		$grid->display_as('nip','NIP / Pegawai');
		$grid->display_as('id_group','Group Pengguna');
		$grid->display_as('confirm_password','Ulangi Password');
		// CUSTOM BUTTON ACTION
		//$grid->add_action('', '','system_configuration/user_password','ui-icon ui-icon-key pengguna_password_cmd');

		//$grid->unset_back_to_list();
		// UNSET UNECESSARY BUTTON FEATURE
		$grid->unset_export();
		$grid->unset_print();
		$grid->unset_read();
		//$grid->unset_delete();

		// RULES
		$this->grid = $grid;
		$this->grid = $grid;
		
		$this->table  = 'pengguna';
		$this->unique_fields = 'nip';
		$this->pk 	  = 'id_pengguna';
		if($act=='edit' && $this->input->get('change_password')=='true')
		{
			$grid->set_rules('password','Password','required');
			$grid->set_rules('confirm_password','Ulangi Password','required');
		}
		else
		{
		$grid->set_rules('nip','NIP','required|callback_unique_value');
		$grid->set_rules('password','Password','required');
		$grid->set_rules('confirm_password','Ulangi Password','required');
		$grid->set_rules('id_group','Group Pengguna','required');
		$grid->set_rules('status','Status','required');
		
		}
		// RENDER THE GRID
		$output = $grid->render();
		$this->load->view('master/pengguna/grid',$output);
	}
	///
	public function group_pengguna()
	{
		//$this->load->vars('list_title','User Management');
		//$this->load->vars('tool_action_width','69px');

		$grid = new grocery_CRUD();
		

		//$this->grid->get_form_validation()->set_message('required','Anda belum menginputkan %s.');
		//SET THEME
		$grid->set_theme('flexigrid');
		$grid->set_view_path('master/group_pengguna/gc_view/');


		//SET TABLE
		$grid->set_table('group_pengguna');
		
		// SET DISPLAYED COLUMN
		$grid->columns('group');
		$grid->fields('group');
		
		// SET SUBJECT
		$grid->set_subject('Group Pengguna');


		$grid->unset_export();
		$grid->unset_print();
		$grid->unset_read();
		//$grid->unset_delete();

		// RULES
		$this->grid = $grid;
		$this->table  = 'group_pengguna';
		$this->unique_fields = 'group';
		$this->pk 	  = 'id_group';

		$grid->set_rules('group','Group','required|callback_unique_value');
		// RENDER THE GRID
		$output = $grid->render();
		$this->load->view('master/group_pengguna/grid',$output);
	}
	public function jabatan()
	{
		//$this->load->vars('list_title','User Management');
		//$this->load->vars('tool_action_width','69px');

		$grid = new grocery_CRUD();
		

		//$this->grid->get_form_validation()->set_message('required','Anda belum menginputkan %s.');
		//SET THEME
		$grid->set_theme('flexigrid');
		


		//SET TABLE
		$grid->set_table('jabatan');
		
		// SET DISPLAYED COLUMN
		$grid->columns('jabatan');
		$grid->fields('jabatan');
		
		// SET SUBJECT
		$grid->set_subject('Jabatan');


		$grid->unset_export();
		$grid->unset_print();
		$grid->unset_read();
		//$grid->unset_delete();

		// RULES
		$this->grid   = $grid;
		$this->table  = 'jabatan';
		$this->unique_fields = 'jabatan';
		$this->pk 	  = 'id_jabatan';

		$grid->set_rules('jabatan','jabatan','required|callback_unique_value');
		// RENDER THE GRID
		$output = $grid->render();
		$this->load->view('master/jabatan/grid',$output);
	}
	public function golongan()
	{
		//$this->load->vars('list_title','User Management');
		//$this->load->vars('tool_action_width','69px');

		$grid = new grocery_CRUD();
		

		//$this->grid->get_form_validation()->set_message('required','Anda belum menginputkan %s.');
		//SET THEME
		$grid->set_theme('flexigrid');
		


		//SET TABLE
		$grid->set_table('golongan');
		
		// SET DISPLAYED COLUMN
		$grid->columns('golongan');
		$grid->fields('golongan');
		
		// SET SUBJECT
		$grid->set_subject('Golongan');


		$grid->unset_export();
		$grid->unset_print();
		$grid->unset_read();
		//$grid->unset_delete();

		// RULES
		$this->grid = $grid;
		$this->table  = 'golongan';
		$this->unique_fields = 'golongan';
		$this->pk 	  = 'id_golongan';
		$grid->set_rules('golongan','Golongan','required|callback_unique_value');
		// RENDER THE GRID
		$output = $grid->render();
		$this->load->view('master/golongan/grid',$output);
	}
	public function pegawai($action='',$token='')
	{
		if($action == 'get_profile' && $token != '')
		{
			$data = $this->grid_model->get_pegawai_info($token);
			echo json_encode(array('success'=>count($data) > 0,'result'=>$data));
			exit;
		}	
		//$this->load->vars('list_title','User Management');
		//$this->load->vars('tool_action_width','69px');

		$grid = new grocery_CRUD();
		

		//$this->grid->get_form_validation()->set_message('required','Anda belum menginputkan %s.');
		//SET THEME
		$grid->set_theme('flexigrid');
		


		//SET TABLE
		$grid->set_table('pegawai');
		
		// SET DISPLAYED COLUMN
		$grid->columns('nama','nip','id_jabatan','id_golongan','instansi','atasan');
		$grid->fields('nama','nip','id_jabatan','id_golongan','instansi','atasan');
		
		// SET SUBJECT
		$grid->set_subject('pegawai');
		$grid->set_relation('id_golongan','golongan','golongan');
		$grid->set_relation('id_jabatan','jabatan','jabatan');

		$nip_list = $this->grid_model->pegawai_dropdown("nip","nama","-",false);
		$grid->field_type('atasan','dropdown',$nip_list);

		$grid->display_as('id_jabatan','Jabatan');
		$grid->display_as('id_golongan','Golongan');

		$grid->display_as('nip','NIP');

		$grid->unset_export();
		$grid->unset_print();
		$grid->unset_read();
		//$grid->unset_delete();

		// RULES
		$this->grid = $grid;
		$this->table  = 'pegawai';
		$this->unique_fields = 'nip';
		$this->pk 	  = 'id_pegawai';

		$grid->set_rules('nama','Nama','required');
		$grid->set_rules('nip','NIP','required|callback_unique_value');
		// RENDER THE GRID
		$output = $grid->render();
		$this->load->view('master/pegawai/grid',$output);
	}

	public function aktifitas_saya($act='',$token='')
	{
		$grid = new grocery_CRUD();
		



		//SET THEME
		$grid->set_theme('flexigrid');
		$grid->set_view_path('master/aktifitas_saya/gc_view/');
		//$grid->set_model('aktifitas_pegawai_model');
		// if($grid_mode != 'default')
		// {
			
		// 	$grid->get_model()->set_grouping();
		// }
		// else
		// {
		// 	$grid->get_model()->unset_grouping();
		// 	$grid->where('nip',$token);
		// }
		//$mode = $this->session->userdata('aktifitas_pegawai_mode');
		//$this->load->vars('mode',$mode);

		// if($mode != 'Pegawai' && $mode != 'Staf')
		// {
		// 	$gid_list = $this->config->item('acl_gid');
		// 	$grid->where('id_group',$gid_list[$mode]);
			
		// }

		// if($mode == 'Staf')
		// {
		// 	$atasan = $this->LoginInfo->GetUserInfo('id_pegawai');
		// 	$grid->where('atasan',$atasan);
				
		// }

		$tipe_admin = $this->LoginInfo->getUserInfo('tipe_admin');
		$nip = $this->LoginInfo->getUserInfo('nip');

		// if($tipe_admin != 'Lurah')
		// {
		// 	$grid->unset_add();
		// 	$grid->unset_delete();
		// 	$grid->unset_edit();
		// }
		// else
		// {

		// }


		//SET TABLE
		$grid->set_table('aktifitas_pegawai');
		$grid->where('nip',$nip) ; 
		// SET DISPLAYED COLUMN
		$grid->unset_columns('nip','id_jabatan','verifikasi','tgl_entry','hari','waktu_mulai','waktu_selesai','atasan');
		$grid->display_as('tgl_kegiatan','Tanggal Kegiatan');
		$grid->display_as('tgl_entry','Tanggal Entri');
		//$grid->unset_fields('verifikasi');
		// CHANGE TO DROPDOWN
		// $nip_list = $this->grid_model->pegawai_dropdown();
		// $grid->field_type('nip','dropdown',$nip_list);
		// SET SUBJECT
		$grid->set_subject('Aktifitas ' . $mode);
		// $grid->set_relation('id_golongan','golongan','golongan');
		// $grid->set_relation('id_jabatan','jabatan','jabatan');
		// $grid->set_relation('atasan','pegawai','nama');

		// $grid->display_as('id_jabatan','Jabatan');
		// $grid->display_as('id_golongan','Golongan');

		$grid->display_as('nip','NIP / Nama Pegawai');

		$grid->unset_export();
		$grid->unset_print();
		//$grid->unset_read();
		//$grid->unset_delete();
		$grid->field_type('verifikasi','dropdown',array('Ya'=>'Ya','Tidak'=>'Tidak'));
		$grid->field_type('uraian_kegiatan','text');
		$grid->unset_texteditor('uraian_kegiatan');
		$grid->unset_texteditor('hasil');

		$grid->field_type('waktu_mulai','time');
		$grid->field_type('waktu_selesai','time');
		
		// RULES
		$this->grid = $grid;
		// $nip_selector = form_dropdown('nip',$nip_list,'');
		// $this->load->vars('nip_selector',$nip_selector);
		// print_r($nip_selector);
		// die();
		
		$grid->set_rules('nip','NIP','required');
		$grid->set_rules('tgl_kegiatan','Tanggal Kegiatan','required');
		$grid->set_rules('waktu_selesai','Waktu Mulai','required');
		$grid->set_rules('waktu_mulai','Waktu Selesai','required');
		$grid->set_rules('uraian_kegiatan','Uraian Pekerjaan','required');
		$grid->set_rules('hasil','Hasil / Output','required');
		// RENDER THE GRID
		$output = $grid->render();
		// $this->load->vars('user_info',$this->LoginInfo->getUserInfo());

		//$nip_selector = form_dropdown('nip_selector',$this->grid_model->pegawai_dropdown());
		//$this->load->vars('nip_selector',$nip_selector);
		//if($grid_mode != 'default')
		$this->load->view('master/aktifitas_saya/grid',$output);
		//else
		//	$this->load->view('master/aktifitas_pegawai/grid_inline',$output);
	}
	public function aktifitas_pegawai($act='',$token='')
	{
		
		$grid_mode = $act;
		if($act == 'cetak_pdf')
		{
			$nip = $token;
			if(!empty($nip))
			{
				$lurah = $this->db->where('b.jabatan','Lurah')
								  ->join('jabatan b','b.id_jabatan=a.id_jabatan')
								  ->get('pegawai a')->row();
				// print_r($lurah);
				// die();
				$this->load->vars('lurah',$lurah);
				$tahun = $this->input->get('tahun');
				//echo $tahun;
				if(empty($tahun))
					$tahun = date('Y');
				$nip = $token;
				$rs  = $this->db->where('nip',$nip);
				if(!empty($tahun))
				{
					$rs->where('YEAR(tgl_kegiatan)='."'$tahun'");
				}
				$data = array(
					'data_aktifitas' => $this->db->where('nip',$nip)->get('aktifitas_pegawai')->result(),
					'pegawai' =>(object) $this->grid_model->get_pegawai_info($nip),
					'tahun'=>$tahun
				);
				$html = $this->load->view('master/aktifitas_pegawai/cetak_pdf',$data,TRUE);
				$this->load->helper('dompdf');
				define('DEFAULT_PDF_PAPER_SIZE', 'folio');
				
				load_dompdf();
				$dompdf = new DOMPDF();
				// some code
				$dompdf->set_paper(DEFAULT_PDF_PAPER_SIZE, 'portrait');
				$dompdf->load_html($html);
				// $paper_size = array(0,0,360,360);
				// $dompdf->set_paper($paper_size);
				$dompdf->render();
				$dompdf->stream("CETAK-AKTIFITAS_PEGAWAI-{$tahun}.pdf", array("Attachment" => 0));

				return;
			}
		}
		else if($act == 'hapus_semua')
		{
			$nip = $token;
			if(!empty($nip))
			{
				$this->db->where('nip',$nip)->delete('aktifitas_pegawai');

				echo $nip;
				return;
			}
		}
		else if($act == 'ubah_verifikasi')
		{
			$id_aktifitas = $token;
			if(!empty($id_aktifitas))
			{
				$this->db->where('id_aktifitas',$id_aktifitas)->update('aktifitas_pegawai',array('verifikasi'=>'Ya'));

				echo $id_aktifitas;
				return;
			}
		}
		else if($act == 'data' && $token != '')
		{
			$tahun = $this->input->get('tahun');
			if(empty($tahun))
					$tahun = date('Y');
			$nip = $token;
			$rs  = $this->db->where('nip',$nip);
			if(!empty($tahun))
			{
				$rs->where('YEAR(tgl_kegiatan)='."'$tahun'");
			}				
			$rs = $this->db->get('aktifitas_pegawai')->result_object();
			
			$this->load->vars('rs',$rs);
			
			$this->load->view('master/aktifitas_pegawai/tr.php');
			


			

			return;
		}
		else if($act=='set_mode' && $token != '') 
		{
			$this->session->set_userdata('aktifitas_pegawai_mode',$token);
			redirect('master/aktifitas_pegawai');
			exit;
		}
	
		$grid = new grocery_CRUD();
		



		//SET THEME
		$grid->set_theme('flexigrid');
		$grid->set_view_path('master/aktifitas_pegawai/gc_view/');
		$grid->set_model('aktifitas_pegawai_model');
		if($grid_mode != 'default')
		{
			
			$grid->get_model()->set_grouping();
		}
		else
		{
			$grid->get_model()->unset_grouping();
			$grid->where('nip',$token);
		}
		$mode = $this->session->userdata('aktifitas_pegawai_mode');
		$this->load->vars('mode',$mode);

		if($mode != 'Pegawai' && $mode != 'Staf')
		{
			$gid_list = $this->config->item('acl_gid');
			$grid->where('id_group',$gid_list[$mode]);
			
		}

		if($mode == 'Staf')
		{
			$atasan = $this->LoginInfo->GetUserInfo('id_pegawai');
			$grid->where('atasan',$atasan);
				
		}

		$tipe_admin = $this->LoginInfo->getUserInfo('tipe_admin');

		if($tipe_admin != 'Lurah')
		{
			$grid->unset_add();
			$grid->unset_delete();
			$grid->unset_edit();
		}
		else
		{

		}


		//SET TABLE
		$grid->set_table('aktifitas_pegawai');
		
		// SET DISPLAYED COLUMN
		$grid->unset_columns('id_jabatan','verifikasi','tgl_entry','hari','waktu_mulai','waktu_selesai','atasan');
		$grid->display_as('tgl_kegiatan','Tanggal Kegiatan');
		$grid->display_as('tgl_entry','Tanggal Entri');
		//$grid->fields('jabatan');
		// CHANGE TO DROPDOWN
		$nip_list = $this->grid_model->pegawai_dropdown();
		$grid->field_type('nip','dropdown',$nip_list);
		// SET SUBJECT
		$grid->set_subject('Aktifitas ' . $mode);
		// $grid->set_relation('id_golongan','golongan','golongan');
		// $grid->set_relation('id_jabatan','jabatan','jabatan');
		// $grid->set_relation('atasan','pegawai','nama');

		// $grid->display_as('id_jabatan','Jabatan');
		// $grid->display_as('id_golongan','Golongan');

		$grid->display_as('nip','NIP / Nama Pegawai');

		$grid->unset_export();
		$grid->unset_print();
		//$grid->unset_read();
		//$grid->unset_delete();
		$grid->field_type('verifikasi','dropdown',array('Ya'=>'Ya','Tidak'=>'Tidak'));
		$grid->field_type('uraian_kegiatan','text');
		$grid->unset_texteditor('uraian_kegiatan');
		$grid->unset_texteditor('hasil');

		$grid->field_type('waktu_mulai','time');
		$grid->field_type('waktu_selesai','time');
		
		// RULES
		$this->grid = $grid;
		$nip_selector = form_dropdown('nip',$nip_list,'');
		$this->load->vars('nip_selector',$nip_selector);
		// print_r($nip_selector);
		// die();
		
		$grid->set_rules('nip','NIP','required');
		$grid->set_rules('tgl_kegiatan','Tanggal Kegiatan','required');
		$grid->set_rules('waktu_selesai','Waktu Mulai','required');
		$grid->set_rules('waktu_mulai','Waktu Selesai','required');
		$grid->set_rules('uraian_kegiatan','Uraian Pekerjaan','required');
		$grid->set_rules('hasil','Hasil / Output','required');
		// RENDER THE GRID
		$output = $grid->render();
		// $this->load->vars('user_info',$this->LoginInfo->getUserInfo());

		//$nip_selector = form_dropdown('nip_selector',$this->grid_model->pegawai_dropdown());
		$this->load->vars('nip_selector',$nip_selector);
		if($grid_mode != 'default')
			$this->load->view('master/aktifitas_pegawai/grid',$output);
		else
			$this->load->view('master/aktifitas_pegawai/grid_inline',$output);
	}
	public function laporan($act='',$tok='')
	{

		if($act == 'viewer')
		{
			$dt_end	= ID_DateToMySQL($this->input->post('dt_end'));
			$dt_start = ID_DateToMySQL($this->input->post('dt_start'));
			
			$nip = $this->input->post('nip');
			

			
			if(!empty($nip))
			{
				$atasan = $this->input->post('atasan');


				$lurah = $this->db->where('b.jabatan','Lurah')
								  ->join('jabatan b','b.id_jabatan=a.id_jabatan')
								  ->get('pegawai a')->row();
				// print_r($lurah);
				// die();
				$this->load->vars('lurah',$lurah);

				$rs = $this->db->select('*')
						   ->where("(DATE(tgl_kegiatan) >= DATE('$dt_start') AND DATE(tgl_kegiatan) <= DATE('$dt_end') )")
						   ->where('nip',$nip)
						   ->get('aktifitas_pegawai')
						   ->result_object();
				//$tahun = $this->input->get('tahun');
				//echo $tahun;
				
				$data = array(
					'data_aktifitas' => $rs,
					'pegawai' =>(object) $this->grid_model->get_pegawai_info($nip),
					'periode' => array('start'=>$this->input->post('dt_start'),'end'=>$this->input->post('dt_end'))
				);
				$html = $this->load->view('master/aktifitas_pegawai/cetak_pdf',$data,TRUE);
				$this->load->helper('dompdf');
				define('DEFAULT_PDF_PAPER_SIZE', 'folio');
				
				load_dompdf();
				$dompdf = new DOMPDF();
				// some code
				$dompdf->set_paper(DEFAULT_PDF_PAPER_SIZE, 'portrait');
				$dompdf->load_html($html);
				// $paper_size = array(0,0,360,360);
				// $dompdf->set_paper($paper_size);
				$dompdf->render();
				$dompdf->stream("LAP-AKT-PGW_".$data['pegawai']->nama.'_'.date('dmY',strtotime($dt_start)).'_'.date('dmY',strtotime($dt_end)).".pdf");

				return;
			}
			return;	
		}	
		else if($act == 'count'){
			$dt_end	= ID_DateToMySQL($this->input->post('dt_end'));
			$dt_start = ID_DateToMySQL($this->input->post('dt_start'));
			
			$nip = $this->input->post('nip');
			$atasan = $this->input->post('atasan');

			$rs = $this->db->select('COUNT(id_aktifitas) as count')
						   ->where("(DATE(tgl_kegiatan) >= DATE('$dt_start') AND DATE(tgl_kegiatan) <= DATE('$dt_end') )")
						   ->where('nip',$nip);
			$rs = $this->db->get('aktifitas_pegawai')
						   ->row()->count;

			echo $rs;
			return;	
		}
		else if($act=='setup'){
			$periode = array(
				'start_date' => $this->input->post('start_date'),
				'end_date' => $this->input->post('end_date'),
			);
		}
		else
		{
			$nip_list = $this->grid_model->pegawai_dropdown();
			$nip_selector = form_dropdown('nip',$nip_list,'');
			$this->load->vars('nip_selector',$nip_selector);
			$this->load->view('master/laporan/form');
		}
	}
}